package com.sai.jsai.module.system.controller;

import com.sai.jsai.common.base.vo.PageResult;
import com.sai.jsai.common.base.vo.RestResult;
import com.sai.jsai.module.system.controller.vo.SysRoleCreateReqVO;
import com.sai.jsai.module.system.controller.vo.SysRolePageReqVO;
import com.sai.jsai.module.system.controller.vo.SysRoleRespVO;
import com.sai.jsai.module.system.dal.entity.SysRole;
import com.sai.jsai.module.system.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.sai.jsai.module.system.convert.SysRoleConvert.INSTANCE;

/**
 * @author jisai
 * @version 0.0.1
 * @Description TODO
 * @createTime 2024/10/26
 */
@Tag(name = "系统管理 - 角色管理")
@RestController
@RequestMapping("/system")
@Validated
public class SysRoleController {

    @Resource
    SysRoleService sysRoleService;

    @PostMapping("/role")
    @Operation(summary = "创建角色")
    public RestResult<SysRoleRespVO> create(@Valid @RequestBody SysRoleCreateReqVO createReqVO) {
        SysRole sysRole = sysRoleService.create(createReqVO);
        return RestResult.success(INSTANCE.convertToVO(sysRole));
    }

    @GetMapping("/roles")
    @Operation(summary = "分页查询角色列表")
    public RestResult<PageResult<SysRoleRespVO>> page(SysRolePageReqVO pageReqVO) {
        return RestResult.success(
                INSTANCE.convertPageResult(sysRoleService.page(pageReqVO), INSTANCE::convertToVO)
        );
    }

}
